#include<iostream>
#include"doublelinkedlist.h"
/// @brief 外部函数find，用于在_list中寻找data为_val的迭代器并返回;
/// @tparam DT 数据模板DT;
/// @param _list 传入的DoubleLinkedList<DT>类;
/// @param _val 传入的所寻找的数据值;
/// @return 若找到返回对应迭代器值，若未能找到则返回空迭代器;
template <typename DT>
typename DoubleLinkedList<DT>::iterator find (DoubleLinkedList<DT> & _list,const DT & _val)
{
    typename DoubleLinkedList<DT>::iterator p = _list.begin();
    typename DoubleLinkedList<DT>::iterator q;
    int i = 1;
    for (p = _list.begin(); *p != _val; ++p)
    {
        if (i == _list.size())
        {
            std::cout << "Not found." << std::endl;
            return q;
        }
        i++;
    }
    std::cout << "Found at the " << i << " position of the list" << std::endl;
    return p;
}

int main()
{
    DoubleLinkedList<int> L;
    DoubleLinkedList<int>::iterator iter;
    for(int i = 1; i <= 5; i++)
    {
        L.push_back(i);
    }
    L.printList();
    iter = find(L,3);
    L.erase(iter);
    L.printList();
    iter = find(L,3);
    return 0;
}
